<div class="layui-card">

    <div class="layui-card-body">
        <div class="layui-form toolbar">
            <div class="layui-inline layui-show-xs-block">
                <input class="layui-input" autocomplete="off" placeholder="日期" name="start" id="start"></div>
            <button id="menus-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <!-- 数据表格 -->
        <table class="layui-table" id="finance-table" lay-filter="menus-table"></table>
    </div>
</div>

<script>


    layui.use(['form', 'table', 'util', 'config', 'admin', 'formSelects', 'treetable','laydate'],function () {
        var laydate=layui.laydate;
        var table = layui.table;
        var layer = layui.layer;
        var admin = layui.admin;
        var treetable = layui.treetable;
        var config = layui.config;
        var arr = ['2021-7-30','2021-7-9','2021-7-13','2021-7-20','2021-06-20'];//不可选日期数组
        //执行一个laydate实例
        laydate.render({
            elem: '#start', //指定元素
            ready: function(){
                var elem = $(".layui-laydate-content");//获取table对象
                layui.each(elem.find('tr'), function (trIndex, trElem) {//遍历tr
                    layui.each($(trElem).find('td'), function (tdIndex, tdElem) {
                        //遍历td
                        var tdTemp = $(tdElem);
                        if (tdTemp.hasClass('laydate-day-next') || tdTemp.hasClass('laydate-day-prev')) {
                            return;
                        }
                        // if (tdIndex == 1) { //此时周一不可选
                        //     //此处判断，是1的加上laydate-disabled，0代表星期日
                        //     tdTemp.addClass('laydate-disabled');
                        // }
                        if(arr.indexOf(tdTemp.attr("lay-ymd"))>-1){//指定数组中的日期不可选
                            tdTemp.addClass('laydate-disabled');
                        }
                    });
                });
            },
            done: function(value, date){
                alert("我选中的日期！"+value);
            }
        });
        // 渲染表格
        var renderTable = function () {
            table.render({

                elem: '#finance-table',
                url: config.base_server + 'api-administrators/finance/detailed',
                where: {
                    access_token: config.getToken().access_token
                },

                page: true,
                parseData: function (res) {
                    console.log(res)
                    return{
                        "code":0,
                        "msg":"",
                        "total":res.data.total,
                        "data":res.data.list,
                        "count":res.data.total,
                    };
                },
                totalRow: true,
                cols: [[
                    {type: 'numbers',totalRowText: '合计'},
                    {field: 'orcode', minWidth: 200, title: '订单号'},
                    {field: 'stname', title: '工位名称'},
                    {field: 'letime',  align: 'center', title: '租赁时间'},
                    {field: 'prices',  align: 'center', title: '订单价格',sort: true, totalRow: true},
                    {field: 'crtime', title: '创建时间'},
                ]]
            });
        };

        renderTable();

        // 工具条点击事件
        table.on('tool(menus-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
                showEditModel(data);
            } else if (layEvent === 'del') {
                layer.confirm('确定删除此菜单吗？', function () {
                    layer.load(2);

                    admin.req('api-manage/menus/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (0 == data.code) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            renderTable();
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'DELETE');

                });
            }
        });

        // 显示编辑弹窗
        var showEditModel = function (data) {
            debugger ;
            if (data){
                data.isMenu = data.isMenu.toString();
                data.hidden = data.hidden.toString();
            }
            var title = data ? '修改菜单' : '添加菜单';
            admin.putTempData('t_menus', data);

            admin.popupCenter({
                title: title,
                path: 'pages/system/menus_form.html',
                finish: function () {
                    renderTable();
                }
            });

        };

        // 搜索按钮点击事件
        $('#menus-btn-search').click(function () {
            var keyword = $('#start').val();
            table.reload('finance-table', {where: {crtime: keyword}});
        });
    });
</script>